package com.woniu.job.filter;

import com.woniu.job.entity.User;

import javax.servlet.*;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


public class LoginFilter implements Filter{
	@Override
	public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain chain)
			throws IOException, ServletException {
		//System.out.println("进了过滤器");
		HttpServletRequest request=(HttpServletRequest)arg0;
		HttpServletResponse response=(HttpServletResponse)arg1;
			Cookie[]cookies=request.getCookies();
			String[]cooks=null;
			User user=new User();
			if(cookies!=null){
				for(Cookie coo:cookies){
					String aa=coo.getValue();
						cooks=aa.split("==");
						if(cooks.length==3) {
							user.setAccount(cooks[0]);
							//System.out.println(user.getAccount());
							user.setPassword(cooks[1]);
							user.setId(cooks[2]);
							request.getSession().setAttribute("user",user);
						}
				}
			}
		chain.doFilter(request, response);
	}

}
